package com.jason.queue;

import lombok.SneakyThrows;

import java.util.Random;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;

/**
 * 消费者
 */
public class Consumer implements Runnable{


    private BlockingQueue<Integer> queue;

    public Consumer(BlockingQueue<Integer> queue) {
        this.queue = queue;
    }

    @SneakyThrows
    @Override
    public void run() {
        //模拟消费者，消费者一直进行消费
        while(true){
            Thread.sleep(new Random().nextInt(1000));
            queue.take();
            System.out.println(Thread.currentThread().getName() +" 消费了 " +queue.size());
        }
    }
}
